package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.api.db.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageResult queryBlacklist(Long userId, Integer page, Integer pagesize) {
        Page<UserInfo> page1 = new Page<>(page, pagesize);
        IPage<UserInfo> page2 = blackListMapper.findByPage(page1, userId);
        long total = page2.getTotal();
        return new PageResult(page,pagesize,(int) total,page2.getRecords());
    }


    @Override
    public void deleteBlacklist(Long blackUserId, Long userId) {
        //        DELETE FROM tb_black_list WHERE black_user_id=20 AND user_id=??

        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BlackList::getBlackUserId,blackUserId);
        queryWrapper.lambda().eq(BlackList::getUserId,userId);
        blackListMapper.delete(queryWrapper);


    }

}
